package com.wyl.interaction.firstpage


import android.view.View
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import com.wuhenzhizao.titlebar.widget.CommonTitleBar
import com.wyl.interaction.R
import com.wyl.libbase.base.BaseFragment
import com.wyl.libbase.extend.onclick
import com.wyl.libbase.extend.toast
import kotlinx.android.synthetic.main.interaction_fragment.*
import kotlinx.android.synthetic.main.interaction_title.*
import kotlinx.android.synthetic.main.interaction_title.view.*


class InteractionFragment : BaseFragment() {

//    private val titles by lazy {
//        arrayOf(
//            context?.string(R.string.interaction),
//            context?.string(R.string.join)
//        )
//    }


    override fun getLayoutId(): Int = R.layout.interaction_fragment

    override fun initView(view: View) {
        titleBar.apply {
            setListener { _, action, _ ->
                when (action) {
                    CommonTitleBar.ACTION_RIGHT_BUTTON -> toast("heheda")
                    else -> {
                    }
                }
            }
        }

        tab1.onclick {
            if (tab1.textSize == 16f) return@onclick
            tab1.textSize = 16f
            tab2.textSize = 13f
        }

        titleBar.leftCustomView.tab2.onclick {
            if (tab2.textSize == 16f) return@onclick
            tab2.textSize = 16f
            tab1.textSize = 13f

        }

        viewPager.adapter = PagerAdapter(
            childFragmentManager,
            listOf(
                InteractionChildFragment(),
                InteractionChildFragment()
            )
        )
    }

    override fun loadData() {

    }

//    private val mAdapter by lazy {
//        SingleTypeAdapter(context!!, R.layout.interaction_item, dataSource)
//    }
//
//    override fun loadData() {
//        binding.include.refreshLayout.startRefresh()
//    }
//
//
//    override fun refresh() {
//        CountDownUtils.delay(1) {
//            dataSource.clear()
//            refresh.set(false)
//            repeat(6) { dataSource.add("") }
//        }
//
//    }
//
//    override fun loadMore() {
//        CountDownUtils.delay(1) {
//            loadMore.set(false)
//            repeat(4) { dataSource.add("") }
//        }
//    }

}

internal class PagerAdapter(
    fragmentManager: FragmentManager,
    private val fragments: List<Fragment>
) : FragmentPagerAdapter(fragmentManager) {

    override fun getItem(position: Int): Fragment {
        return fragments[position]
    }

    override fun getCount(): Int {
        return fragments.size
    }

}
